<template>
  <div class="todo-footer" v-show="all">
    <label>
      <input type="checkbox" v-model="isAll" />
    </label>
    <span>
      <span>已完成{{ isChecked }}</span> / 全部{{ all }}</span
    >
    <button class="btn btn-danger" @click="removerHandler">
      清除已完成任务
    </button>
  </div>
</template>

<script>
export default {
  name: "MyFooter",
  props: ["TodoList", "isAllCheckedTodo", "removerTod"],
  computed: {
    all() {
      return this.TodoList.length;
    },
    isChecked() {
      return this.TodoList.reduce(
        (pre, todo) => pre + (todo.done === true ? 1 : 0),
        0
      );
    },
    isAll: {
      get() {
        return this.all === this.isChecked && this.all > 0;
      },
      set(val) {
        this.isAllCheckedTodo(val);
      },
    },
  },
  methods: {
    removerHandler() {
      this.removerTod();
    },
  },
};
</script>

<style scoped lang="less">
/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;

  label {
    display: inline-block;
    margin-right: 20px;
    cursor: pointer;

    input {
      position: relative;
      top: -1px;
      vertical-align: middle;
      margin-right: 5px;
    }
  }

  button {
    float: right;
    margin-top: 5px;
  }
}
</style>
